package com.wandian.cqcsk.mvvm.mine.mywallet;

import android.os.Bundle;
import android.view.View;

import androidx.databinding.DataBindingUtil;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.mylib.libcore.config.RouterConfig;
import com.mylib.libcore.mvvm.BaseMVVMActivity;
import com.mylib.libcore.utils.StatusBarUtils;
import com.mylib.libcore.utils.ToastUtil;
import com.mylib.libcore.utils.UIUtils;
import com.wandian.cqcsk.R;
import com.wandian.cqcsk.databinding.ActivityMyWalletBinding;

/**
 * @author Administrator
 * @date 2019/12/18-14:28
 * @description 我的钱包
 **/
@Route(path = RouterConfig.ROUTER_ACTIVITY_MY_WALLET)
public class MyWalletActivity extends BaseMVVMActivity<MyWalletViewModel> {
    private ActivityMyWalletBinding dataBinding;
    private boolean canTX = false;//是否能提现
    @Override
    public void init(Bundle savedInstanceState) {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_my_wallet);
        dataBinding.setLifecycleOwner(this);
        dataBinding.setViewModel(mViewModel);
        initViewData();
        initClink();
    }

    @Override
    protected void onResume() {
        super.onResume();
        mViewModel.getUserWallet();
    }

    private void initViewData(){
        //设置状态颜色和字体黑色
        StatusBarUtils.with(this,false)
                .setIsActionBar(false)
                .clearActionBarShadow()
                .setDrawable(getResources().getDrawable(com.mylib.libcore.R.drawable.sys_color))
                .init();
        dataBinding.bindSysToolBar.toolBarTvTitle.setText("我的钱包");
        dataBinding.bindSysToolBar.toolBarTitleRight.setText("提现记录");
        dataBinding.bindSysToolBar.toolBarTitleRight.setVisibility(View.VISIBLE);

        mViewModel.myWalletBean.observe(this,bean->{
            if(!UIUtils.isEmpty(bean)){
                if(bean.getIsApply()==0){
                    canTX = true;
                }else {
                    canTX = false;
                }
                dataBinding.tvCoinNumber.setText(bean.getGold()+"");
                dataBinding.tvMoneyNumber.setText(bean.getAmount()+"元");
            }
        });
    }
    private void initClink(){
        dataBinding.bindSysToolBar.toolBarIvBack.setOnClickListener(v -> {
            finish();
        });
        //提现记录
        dataBinding.bindSysToolBar.toolBarTitleRight.setOnClickListener(v -> ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_TX_HISTORY).navigation());
        //提现记录
        dataBinding.rlLjdz.setOnClickListener(v -> ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_TX_HISTORY).navigation());
        //金币记录
        dataBinding.rlMineCoin.setOnClickListener(v -> ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_COIN_HISTORY).navigation());
        //提现选择
        dataBinding.llWx.setOnClickListener(v -> {
            if(!canTX){
                ToastUtil.show("今日提现申请已上限");
                return;
            }
            ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_TX_CHOOSE).navigation();
        });
    }


}
